package datastructure.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XY
 * @version 1.0
 * @date 2022/2/28 9:10
 * @Description
 */
public class Leet589 {

    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    List<Integer> temp = new ArrayList<>();

    public List<Integer> preorder(Node root) {
        if(root==null){
            return temp;
        }
        temp.add(root.val);
        if(root.children!=null&&root.children.size()>0){
            for (int i = 0; i < root.children.size(); i++) {
                preorder(root.children.get(i));
            }
        }
        return temp;
    }
}
